<template>
  <u-popup :show="show" mode="center">
    <div class="navigate-container">
      <div class="container-header">
        <u-icon name="close" class="container-header-close" @click="cancel" />
      </div>
      <div class="container-table">
        <div class="container-table-left">
          <div
            v-for="(item, index) in tabs"
            :key="index"
            class="left-item"
            :class="{ 'left-item-active': active_tab === item.component }"
            @click="handleChangeTab(item.component)"
          >
            {{ item.name }}
          </div>
        </div>
        <div class="container-table-right">
          <component
            :is="active_tab"
            @confirm="confirm"
            @cancel="cancel"
            :active="active_tab"
            :ref="active_tab"
          />
        </div>
      </div>
    </div>
  </u-popup>
</template>

<script>
import systemPage from "./components/system-page";
import microPage from "./components/micro-page";
import industryPage from "./components/industry-page";
export default {
  name: "index",
  components: { systemPage, microPage, industryPage },
  props: {
    show: {
      type: Boolean,
      default: false,
    },
  },
  computed: {
    pageData() {
      return this.$store.state.page.page;
    },
    //组件本身属性
    editConfigCom({ pageData, activeIndex }) {
      return pageData.items[activeIndex];
    },
  },
  data() {
    return {
      tabs: [
        {
          name: "系统页面",
          component: "system-page",
        },
        {
          name: "微页面",
          component: "micro-page",
        },
        {
          name: "行业类型",
          component: "industry-page",
        },
      ],
      active_tab: "system-page",
    };
  },
  methods: {
    open(options) {
      this.$emit("update:show", true);
      this.$nextTick(() => {
        this.active_tab = options?.navigateFrom
          ? options?.navigateFrom
          : "system-page";
        this.$nextTick(() => {
          if (options?.path) {
            this.$refs[this.active_tab]?.$refs?.tablePanelRefs.setSelectItem(
              options?.path
            );
          }
        });
      });
    },
    handleChangeTab(e) {
      this.active_tab = e;
    },
    confirm(e) {
      this.$emit("confirm", e);
    },
    cancel() {
      this.$emit("update:show", false);
    },
  },
};
</script>

<style scoped lang="scss">
.navigate-container {
  padding: 20px;
  min-width: 1000px;
  .container {
    //头部
    &-header {
      position: relative;
      width: 100%;
      height: 1.2rem;
      &-close {
        position: absolute;
        right: 0;
        top: 0;
      }
    }
    //表格主题
    &-table {
      display: flex;
      &-left {
        margin-right: 10px;
        .left-item {
          width: 7rem;
          padding: 10px 0;
          text-align: center;
          &-active {
            background-color: #d1d1d1;
            border-radius: 8rpx;
          }
        }
      }
      &-right {
        flex: 1;
      }
    }
  }
  .table-main {
    padding: 0 20px 0 20px;
    .table-confirm {
      display: flex;
      justify-content: flex-end;
      &-btn {
        width: 100px;
      }
    }
    &-search {
      display: flex;
      .u-button {
        width: 100px;
        margin-left: 10px;
      }
    }
  }
}
</style>
